<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>文件上传</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type="text/css">
        .shadow {
            width: 50%;
            height: 300px;
            padding: 20px;
            margin: 20px auto;
            box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
        }
        .dot {
            position: relative;
            width: 100%;
            height: 100%;
            box-sizing: border-box;
            border: dotted 3px #cfcfcf;
        }
        .fake {
            width: 150px;
            height: 50px;
            background: #00b7fe;
            position: absolute;
            top: 50%;
            left: 50%;
            text-align: center;
            line-height: 50px;
            color: #fff;
            border-radius: 5px;
            margin-top: -50px;
            margin-left: -75px;
        }
        .fake:active {
            background: #025670;
        }
        .file-input {
            display: inline-block;
            width: 100%;
            height: 100%;
            position: absolute;
            cursor: pointer;
            left: 0;
            opacity: 0;
        }
        .submit {
            display: block;
            width: 100px;
            height: 30px;
            background: #00b7fe;
            border: solid 3px #00b7fe;
            color: #fff;
            margin: 0 auto;
        }
        .tip {
            position: absolute;
            top: 50%;
            color: #ccc;
            font-size: 18px;
            text-align: center;
            width: 100%;
        }
    </style>
</head>
<body>
    <script>
        function uploadFile() {
            var xmlHttp;
            if (window.XMLHttpRequest) {
                xmlHttp = new XMLHttpRequest();
            }
            else {
                xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
            }
            xmlHttp.onreadystatechange = function() {
                if (xmlHttp.readyState === 4 && xmlHttp.state === 200) {
                    alert('上传成功！');
                }
            }
            xmlHttp.open('post', '/aciton/upload', true);
            xmlHttp.send();
        }
    </script>
    <form id="form" onsubmit="uploadFile()" method="post" enctype="multipart/form-data">
        <div class="shadow">
            <div class="dot">
                <div class="fake">点击选择文件
                    <input type="file" id="file" name="file" class="file-input"/>
                </div>
                <h2 id="tip" class="tip">未选择文件</h2>
            </div>
        </div>
        <button class="submit">开始上传</button>
    </form>
    <script>
        var fileInput = document.getElementById('file');
        var tip = document.getElementById('tip');
        fileInput.addEventListener('change', function() {
            tip.innerHTML = this.value;
        });
    </script>
</body>
</html>